﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Frogism.Core;
using NUnit.Framework;
namespace Frogism.Tests {
  [TestFixture]
  public class BudgetItemTest {
    [Test]
    public void BudgetSpansYears() {
      DateTime startdate = new DateTime(2008, 12, 29);


      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, DateTime.Now, true);
      a.Transactions.Add(transaction);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateWeek(startdate, accounts);

      Assert.AreEqual(50M*4+60M*3, bi.Budget);
    }
    [Test]
    public void Spent() {
      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, DateTime.Now, true);
      a.Transactions.Add(transaction);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateWeek(accounts);
      Assert.AreEqual(99.99M, bi.Spent);
    }
    [Test]
    public void Budget() {
      BudgetItem bi = BudgetItem.CreateWeek(null);
      Assert.AreEqual(BudgetItem.BudgetForDay(DateTime.Now.CleanDate()) * 7, bi.Budget);
    }
    [Test]
    public void BudgetSoFar() {
      DateTime KnownWednseday = new DateTime(2008, 05, 21);
      BudgetItem bi = BudgetItem.CreateWeek(KnownWednseday, null);
      Assert.AreEqual(BudgetItem.BudgetForDay(KnownWednseday) * 4, bi.BudgetSoFar);

    }
    [Test]
    public void BalanceSoFar() {
      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      DateTime KnownWednseday = new DateTime(2008, 05, 21);

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, KnownWednseday, true);
      a.Transactions.Add(transaction);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateWeek(KnownWednseday, accounts);
      Assert.AreEqual(BudgetItem.BudgetForDay(KnownWednseday) * 4 - 99.99M, bi.BalanceSoFar);
    }
    [Test]
    public void Balance() {
      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      DateTime KnownWednseday = new DateTime(2008, 05, 21);

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, KnownWednseday, true);
      a.Transactions.Add(transaction);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateWeek(KnownWednseday, accounts);
      Assert.AreEqual(BudgetItem.BudgetForDay(KnownWednseday) * 7 - 99.99M, bi.Balance);
    }
    [Test]
    public void BalanceSoFarLastWeek() {
      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      DateTime KnownWednseday = new DateTime(2008, 05, 21);

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, KnownWednseday.AddDays(-7), true);
      a.Transactions.Add(transaction);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateLastWeek(KnownWednseday, accounts);
      Assert.AreEqual(BudgetItem.BudgetForDay(KnownWednseday) * 7 - 99.99M, bi.BalanceSoFar);

    }
    [Test]
    public void SpentForWeekOnlyHasThisWeekExpenses() {

      Account a = new Account();
      a.Id = 66;
      a.IsActive = true;
      a.Name = "test";

      DateTime KnownWednseday = new DateTime(2008, 05, 21);

      Transaction transaction = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 99.99M, KnownWednseday.AddDays(-7), true);
      a.Transactions.Add(transaction);

      Transaction transaction2 = new Transaction("Test", a.Id, DBConst.TransactionTypeExpense, 77.77M, KnownWednseday, true);
      a.Transactions.Add(transaction2);

      Collection<IAccount> accounts = new Collection<IAccount>();
      accounts.Add(a);
      BudgetItem bi = BudgetItem.CreateWeek(KnownWednseday, accounts);
      Assert.AreEqual(transaction2.Amount, bi.Spent);


    }
  }

}
